﻿using System.Numerics;

namespace GKS.Extensions {
    public static class ObjectExtensions {
        #region variables

        #endregion

        #region properties

        #endregion

        #region enums

        #endregion

        #region constructors

        #endregion

        #region methods
        /// <summary>
        /// A method that checks if an object is a (standard) numeric or not.
        /// </summary>
        /// <param name="obj">
        /// The object to check for.
        /// </param>
        /// <returns>
        /// TRUE if the specified object is a (standard) numeric, FALSE otherwise.
        /// </returns>
        /// <remarks>
        /// The standard numeric types taken into consideration are:
        ///     - byte
        ///     - sbyte
        ///     - decimal
        ///     - double
        ///     - float
        ///     - int
        ///     - uint
        ///     - long
        ///     - ulong
        ///     - short
        ///     - ushort
        ///     - Complex
        ///     - BigInteger.
        /// </remarks>
        public static bool IsNumeric(this object obj) {
            return obj is byte
                || obj is decimal
                || obj is double
                || obj is float
                || obj is int
                || obj is long
                || obj is sbyte
                || obj is short
                || obj is uint
                || obj is ulong
                || obj is ushort
                || obj is Complex
                || obj is BigInteger;
        }

        public static T CastTo<T>(this object obj) {
            return (T)obj;
        }
        #endregion
    }
}
